import urllib.request
from bs4 import BeautifulSoup

url = 'https://www.gov.cn/yaowen/tupian/202408/content_6967193.htm#2'
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) '
                         "Chrome/108.0.5359.125 Safari/537.36"}

req = urllib.request.Request(url=url, headers=headers)
html = urllib.request.urlopen(req, timeout=10)
bs = BeautifulSoup(html.read(), 'lxml')

print(bs.prettify())
print('***********************************************************************************')
print(bs.find_all('img'))
print('***********************************************************************************')
print(bs.find_all(lambda img: img.name == 'img' and img.has_attr('src') and img.has_attr('class')))
print('***********************************************************************************')
print(bs.find('li').next_element)
print('***********************************************************************************')
print(bs.body.descendants)  #生成器
